const menus = [
  {
    path: '/',
    key: '/',
    label: '系统首页',
  },
  {
    path: '/banner',
    key: '/banner',
    label: '轮播图管理',
    children: [
      {
        path: '/banner/list',
        key: '/banner/list',
        label: '轮播图列表',
      },
      {
        path: '/banner/add',
        key: '/banner/add',
        label: '添加轮播图',
        hidden: true
      }
    ]
  },
  {
    path: '/pro',
    key: '/pro',
    label: '商品管理',
    redirect: '/pro/list',
    children: [
      {
        path: '/pro/list',
        key: '/pro/list',
        label: '商品列表',
      },
      {
        path: '/pro/search',
        key: '/pro/search',
        label: '筛选列表',
      }
    ]
  },
  {
    path: '/account',
    key: '/account',
    label: '账户管理',
    redirect: '/account/list',
    children: [
      {
        path: '/account/list',
        key: '/account/list',
        label: '用户列表',
      },
      {
        path: '/account/admin',
        key: '/account/admin',
        label: '管理员列表',
      }
    ]
  },
  {
    path: '/set',
    key: '/set',
    label: '设置',
    hidden: true
  },
]

const checkedKeys = ['/', '/banner/list', '/pro/list/home', '/set']
// const myCheckedKeys = ['/', '/banner', '/banner/list', '/pro', '/pro/search']
// ['/', '/pro/list/home', '/banner/list'] => ['/', '/pro', '/pro/list', '/pro/list/home', '/banner', '/banner/list']
function getMyCheckedKeys (checkedKeys) {
  const arr = []
  checkedKeys.forEach(item => {
    const newArr = item.split('/')
    newArr.map((_, index) => {
      arr.push(`${newArr.slice(0, index + 1).join('/')}`)
    });
  
  })
  // arr 去重 去空
  return Array.from(new Set(arr))
}
const myCheckedKeys = getMyCheckedKeys(checkedKeys)
console.log(myCheckedKeys)
function getMenuList (menus, myCheckedKeys) {
  const result = getResult(menus)
  function getResult (menus) {
    const arr = []
    menus.forEach(item => {
      if (item.children) {
        if (myCheckedKeys.includes(item.key)) {
          console.log(4, item.key)
          arr.push({ ...item })
          if (item.children) {
            arr[arr.length - 1].children = getResult(item.children)
          }
        } 
        
       
      } else {
        if (myCheckedKeys.includes(item.key)) {
          arr.push({ ...item })
        }
       
      }
    });
    return arr
  }

  return result
}

const result = getMenuList(menus, myCheckedKeys)
console.log(result)